const fs = require("fs");
const path = require("path");
const { convertDatToAss, calculateDatDuration } = require("../src/convert_dat_to_ass");

// Create a simple test DAT file
const testDatContent = `*^Hello$Hello$$$$$#你好#0#2*
*^World$World$$$$$#世界#2#4*
*^Test$Test$$$$$#测试#4#6*`;

const testDatPath = path.join(__dirname, "../temp/test.dat");
const testAssPath = path.join(__dirname, "../temp/test.ass");

// Create temp directory if it doesn't exist
if (!fs.existsSync(path.join(__dirname, "../temp"))) {
  fs.mkdirSync(path.join(__dirname, "../temp"));
}

// Write test DAT file
fs.writeFileSync(testDatPath, testDatContent, "utf8");

// Test conversion
console.log("Testing convertDatToAss function...");
convertDatToAss(testDatPath, testAssPath);

// Test duration calculation
console.log("Testing calculateDatDuration function...");
const duration = calculateDatDuration(testDatPath);
console.log(`Calculated duration: ${duration} seconds`);

// Check if ASS file was created
if (fs.existsSync(testAssPath)) {
  console.log("SUCCESS: ASS file was created successfully");
  const assContent = fs.readFileSync(testAssPath, "utf8");
  console.log("ASS file content preview:");
  console.log(assContent.substring(0, 500) + "...");
} else {
  console.log("ERROR: ASS file was not created");
}

// Clean up test files
// fs.unlinkSync(testDatPath);
// fs.unlinkSync(testAssPath);
